﻿using System;
using System.Data;
using Company.BLL.Utils;
using Company.BLL.WS.GC;
using System.Data.SqlClient;

namespace Company.BLL.GC
{
    public class NguyenPhuLieu : NguyenPhuLieuBase
    {
        public static DataSet WS_GetDanhSachDaDangKy(string maHaiQuan, string maDoanhNghiep)
        {
            GCService service = new GCService();
            return service.NguyenPhuLieu_GetDanhSach(maHaiQuan, maDoanhNghiep);
        }

        public static bool UpdateRegistedToDatabase(string maHaiQuan, string maDoanhNghiep, SqlTransaction transaction)
        {
            // Lấy danh sách từ WEB SERVICE.
            DataSet ds = WS_GetDanhSachDaDangKy(maHaiQuan, maDoanhNghiep);

            // Cập nhật vào CSDL.
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                NguyenPhuLieu npl = new NguyenPhuLieu();
                npl.SoHopDong = row["SoHopDong"].ToString();
                npl.MaHaiQuan = row["MaHaiQuan"].ToString();
                npl.MaDoanhNghiep = row["MaDoanhNghiep"].ToString();
                npl.NgayKy = Convert.ToDateTime(row["NgayKy"]);
                npl.Ma = row["Ma"].ToString().Substring(1);
                npl.Ten = FontConverter.TCVN2Unicode(row["Ten"].ToString());
                npl.MaHS = row["MaHS"].ToString();
                npl.DVT_ID = row["DVT_ID"].ToString();
                npl.SoLuongDangKy = Convert.ToDecimal(row["SoLuongDangKy"]);
                npl.InsertUpdateTransaction(transaction);
            }

            return true;
        }

    }
}